﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.IO;
using OgilvyOne.Borad.DAL;

public partial class admin_vico_getExcle_preorder : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string startTime = Request.QueryString["starTime"];
        string endTime = Request.QueryString["endTime"];
        string strSql = "select id,name,sex,mobile,email,province,city,dealer,budget,mention,capcity,carModel,carColor,carSeat,creatTime,source,channel from preorder where creatTime between '"+startTime+"' and '"+endTime+"' order by creatTime desc ";
        DataSet ds = SQLHelper.Query(strSql);
        output(ds);
    }
    private void output(DataSet ds)
    {

        if (ds.Tables[0].Rows.Count != 0)
        {
            DataTable dt = ds.Tables[0];
            StringWriter sw = new StringWriter();
            //sw.WriteLine(Session["msg"].ToString() + "\t" );
            sw.WriteLine("ID,姓名,称谓,电话号码,邮箱,省,市,经销商,购车预算,购车时间,排量,车型,颜色,坐垫,注册时间,来源,渠道");
            foreach (DataRow dr in dt.Rows)
            {
                sw.WriteLine(dr["id"] + "," + dr["name"] + "," + dr["sex"] + "," + dr["mobile"] + "," + dr["email"] + "," + dr["province"] + "," + dr["city"] + "," + dr["dealer"] + "," + dr["budget"] + "," + dr["mention"] + "," + dr["capcity"] + "," + dr["carModel"] + "," + dr["carColor"] + "," + dr["carSeat"] + "," + dr["creatTime"] + "," + dr["source"] + "," + dr["channel"]);
            }
            sw.Close();
            string sss = DateTime.Today.ToString("yyyyMMdd") + new Random(DateTime.Now.Millisecond).Next(10000).ToString() + ".csv";
            Response.AddHeader("Content-Disposition", "attachment;filename=" + sss);
            Response.ContentType = "application/ms-excel";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            Response.Write(sw);
            Response.End();
        }
    }

}